<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Admins extends Model
{
    protected $hidden=['password'];

    public function role()
    {
        return $this->hasOne(Role::class,'id','role_id');
    }

    public function getData1($time = null, $schoolId = null, $name = null, $teacherName = null,$id=null)
    {

        return $this->alias('ad')
            ->join('classtime ct','ct.admin_id=ad.id')
            ->join('class_student cs','ct.id=cs.classtime_id')
            ->join('invoice_details ivd','ivd.id=cs.invoice_details_id')
            ->join('invoice i','i.id=ivd.invoice_id')
            ->join('student s','s.id=cs.student_id')
            ->when($time,function ($q) use($time){
                $q->whereBetween('ct.start_time',[$time['start_time'],$time['end_time']]);
            })
            ->when($schoolId,function ($q) use($schoolId){
                $q->where('i.school_id',$schoolId);
            })
            ->when($name,function ($q)use($name){
                $q->where('s.name','like',"%$name%");
            })
            ->when($teacherName,function ($q)use($teacherName){
                $q->where('ad.name','like',"%$teacherName%");
            })
            ->when($id,function ($q)use($id){
                $q->where('ad.student_id',$id);
            })
            ->where('cs.state','<>','取消')
            ->field('ad.id,ad.ename,ad.color')
            ->group('ad.id')
            ->select()
            ->toArray();
    }
}
